package com.ubi.core.framework.validation;

import org.apache.commons.lang3.StringUtils;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;
import java.util.regex.Pattern;

public class EmojiPreventValidator implements ConstraintValidator<EmojiPrevent, String> {

    @Override
    public void initialize(EmojiPrevent constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if (StringUtils.isBlank(value))
            return true;
        return !Pattern.compile("[^\\u0000-\\uFFFF]").matcher(value).find();
    }
}
